package com.baylor.server.business.service.impl;

import java.util.Map;

import com.baylor.server.business.constant.BusinessErrorEnum;
import com.baylor.server.business.exception.BusinessException;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.baylor.server.base.util.DynamicSpecifications;
import com.baylor.server.base.util.SearchFilter;
import com.baylor.server.business.entity.Customer;
import com.baylor.server.business.repository.CustomerRespository;
import com.baylor.server.business.service.CustomerService;

@Service
public class CustomerServiceImpl implements CustomerService{

    private static final Logger log=Logger.getLogger(CustomerServiceImpl.class);

	@Autowired
	private CustomerRespository customerRespository;

	public Page<Customer> getCustomerByCondition(
			Map<String, Object> filterParams, Pageable pageable) {
		Map<String, SearchFilter> filters = SearchFilter.parse(filterParams);
		return customerRespository.findAll(DynamicSpecifications.bySearchFilter(filters.values(), Customer.class), pageable);
	}

    @Override
    public void customerRegister(Customer customer) throws BusinessException {

        Customer customervo = customerRespository.findByLoginAccount(customer.getLoginAccount());
        if(customervo!=null)
        {
            BusinessErrorEnum errorMsg = BusinessErrorEnum.CUSTOMER_EXIST;
            throw new BusinessException(errorMsg.getErrorCode(), errorMsg.getErrorMsg());
        }
        customerRespository.save(customer);
    }

    @Override
    public void customerLogin(String loginAccount, String loginPassword) {

    }

    @Override
    public void changePassword(String loginAccount, String oldPassword, String newPassword) {

    }

    @Override
    public void changePwdByCellPhone() {

    }

    @Override
    public void changePwdByEmail() {

    }

    @Override
    public Customer getCustomerById() {
        return null;
    }

}
